package com.example.myapplication.part15;

import android.view.View;
import android.view.ViewGroup;
import androidx.viewpager.widget.PagerAdapter;
import java.util.ArrayList;

public class PageViewAdapter extends PagerAdapter {

    private ArrayList<View> views;

    public PageViewAdapter(ArrayList<View> views) {
        this.views = views;
    }

    @Override
    public int getCount() {
        return views.size(); // 返回视图数量
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object; // 判断视图是否属于当前对象
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = views.get(position); // 获取指定位置的视图
        container.addView(view); // 将视图添加到容器中
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object); // 移除视图
    }
}